#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>

int check_creds(char * name, uint32_t token) {
    if (strcmp("Santo & Johnny", name) == 0) {
        if (token == 0xdeadc0de) {
            return 0;
        }
    }
    return 1;
}

int main() {
    // Disable buffering on stdin and stdout to make network connections better.
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    uint32_t token = 0x41414141;
    char name[64] = {0};

    printf("Name: ");
    read(0, name, 63);
    printf("Token: ");
    read(0, &token, 4);

    printf("Submitted Name: %s\n", name);
    printf("Submitted Token: 0x%x\n", token);

    if (check_creds(name, token) == 0) {
        printf("Success, Welcome %s.\n", name);
        system("/bin/sh");
    }
    else {
        puts("Incorrect credentials.");
    }
}
